package vip.zhenzicheng.algorithm.leetcode.linked_list;

import vip.zhenzicheng.algorithm.ListNode;

/**
 * <a href="https://leetcode.cn/problems/reverse-linked-list/">反转链表 [简单]</a>
 * 给定链表头head，反转链表返回新的头
 * 提示：
 * 链表中节点的数目范围是 [0, 5000]
 * -5000 <= Node.val <= 5000
 *
 * @author zhenzicheng
 * @date: 2022-06-02 11:26
 */
public class ReverseLinkedList_206 {
  public ListNode reverseList(ListNode head) {
    if (head == null) {
      return null;
    }

    ListNode cur = head, pre = null, next;
    while (cur != null) {
      next = cur.next;
      cur.next = pre;
      pre = cur;
      cur = next;
    }

    return pre;
  }
}